package core.oauth;

import core.api.DriveApi20;
import core.api.DropBoxApi20;
import core.api.OneDriveApi20;
import org.scribe.builder.ServiceBuilder;
import org.scribe.oauth.OAuthService;

/**
 *
 * @author Admin
 */
public class ServiceFactory {

    public static final String DROPBOX = "dropbox";
    public static final String DRIVE = "drive";
    public static final String ONEDRIVE = "onedrive";

    private static final String DROPBOX_API_KEY = "9231a0npejt32sk";
    private static final String DROPBOX_API_SECRET = "i2v1wh2kv0o0wb8";
    private static final String DROPBOX_CALLBACK = "http://localhost:8080/storagews/api/auth/callback";

//    private static final String DRIVE_API_KEY = "862258043763-j3kgcac5tasr9mlrmigj1mrvcs5398qo.apps.googleusercontent.com";
//    private static final String DRIVE_API_SECRET = "t_4YvXfkMA9ar0ZajTXfTVtD";
//    private static final String DRIVE_CALLBACK = "urn:ietf:wg:oauth:2.0:oob";
//    private static final String DRIVE_SCOPE = "https://www.googleapis.com/auth/drive";
    
    private static final String DRIVE_API_KEY = "862258043763-batlnt2cv2b925imp9vbss6v4b2jouaa.apps.googleusercontent.com";
    private static final String DRIVE_API_SECRET = "tgFGKbugvAEQuj0e5ILeBw4A";
    private static final String DRIVE_CALLBACK = "http://localhost:8080/storagews/api/auth/callback";
    private static final String DRIVE_SCOPE = "https://www.googleapis.com/auth/drive";
    
    private static final String ONEDRIVE_CLIENT_ID = "00000000481144DE";
    private static final String ONEDRIVE_REDIRECT_URI = "https://login.live.com/oauth20_desktop.srf";
    private static final String ONEDRIVE_CLIENT_SECRET = "B3BnnqsuUv1K9y4uAh8i9FRfKysZHaLs";
    private static final String ONEDRIVE_SCOPE = "wl.skydrive";

    public static OAuthService create(String type) {
        switch (type) {
            case DROPBOX:
                return createDropboxAuthService();
            case DRIVE:
                return createDriveAuthService();
            case ONEDRIVE:
                return createOnedriveAuthService();
            default:
                throw new UnsupportedOperationException(type);
        }
    }

    private static OAuthService createDropboxAuthService() {
        return new ServiceBuilder()
                .provider(DropBoxApi20.class)
                .apiKey(DROPBOX_API_KEY)
                .apiSecret(DROPBOX_API_SECRET)
                .callback(DROPBOX_CALLBACK)
                .build();
    }

    private static OAuthService createDriveAuthService() {
        return new ServiceBuilder()
                .provider(DriveApi20.class)
                .apiKey(DRIVE_API_KEY)
                .apiSecret(DRIVE_API_SECRET)
                .callback(DRIVE_CALLBACK)
                .scope(DRIVE_SCOPE)
                .build();
    }

    private static OAuthService createOnedriveAuthService() {
        return new ServiceBuilder()
                .provider(OneDriveApi20.class)
                .apiKey(ONEDRIVE_CLIENT_ID)
                .apiSecret(ONEDRIVE_CLIENT_SECRET)
                .callback(ONEDRIVE_REDIRECT_URI)
                .scope(ONEDRIVE_SCOPE)
                .build();
        
        
    }
}
